﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Authorization.API.Application.Command.OrganizationCommand;

namespace S.Authorization.API.Controllers.Organization
{
    [Route("api/[controller]")]
    [ApiController]
    public class BusinessController : ControllerBase
    {
        private IMediator mediator;
        public BusinessController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增单位
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpPost("AddBusiness")]
        public async Task<IActionResult> AddBusiness(BusinessModelCreateCommand column)
        {
            var result = await mediator.Send(column);
            return Ok(result);
        }
        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="File"></param>
        /// <returns></returns>
        [HttpPost("UpLoad")]
        public async Task<IActionResult> UpLoad(IFormFile File)
        {
            //string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); // 获取当前环境
            //string basePath = ""; // 设置基础路径

            //if (environment == "Development") // 开发环境
            //{
            //    basePath = "http://10.31.56.7:7060/Img/";
            //}
            //else if (environment == "Production") // 生产环境
            //{
            //    basePath = "http://152.136.226.135:7060/Img/";
            //}
            string savePath = Directory.GetCurrentDirectory() + (@"\wwwroot\Img\" + File.FileName);
            using (FileStream stream = new FileStream(savePath, FileMode.Create))
            { 
                File.CopyTo(stream);
                stream.Flush();
            }
            return Ok(File.FileName);
        }

    }
}
